﻿using CPPEI.Coolzon.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Server.CacheData
{
    public class Client
    {
        public int Index { get; set; }
        public string UserAccount { get; set; }
        public string UserIdentity { get; set; }
        public Guid UserId { get; set; }
        /// <summary>
        /// 回调通道
        /// </summary>
        public IMainServiceCallback Callback { get; set; }
        public string AppVersion { get; set; }
        public string AppType { get; set; }

        /// <summary>
        /// 是否处在域中
        /// </summary>
        public bool IsInDomain { get; set; }
        /// <summary>
        /// 用户所处的控制域
        /// </summary>
        public ControlDomain Domain { get; set; }

        /// <summary>
        /// 最新的活跃时间，用于判断用户是否非正常的关闭了程序或者网络中断
        /// </summary>
        public long LatestActiveTicks { get; set; }

        public ClientState State { get; set; }

        /// <summary>
        /// 终端的状态
        /// 最后这个将和State合并
        /// </summary>
        public Service.Contract.ClientStatus Status{ get; set; }

        /// <summary>
        /// 判断客户端是否忙碌，主要是根据Status来判断
        /// </summary>
        /// <returns>true:忙碌,false:不忙碌</returns>
        public bool IsBusy()
        {
            if(Status == Service.Contract.ClientStatus.Syncing
                || Status == Service.Contract.ClientStatus.Loading)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 受控制状态
        /// </summary>
        public ControlState ControlState { get; set; }

        /// <summary>
        /// 是否需要同步视图状态
        /// </summary>
        public bool IsSyncViewState { get; set; }

        public Client()
        {
            IsInDomain = false;
            Index = -1;
            State = ClientState.InHall;
            this.Status = Service.Contract.ClientStatus.Normal;

            ControlState = CacheData.ControlState.UnderControl;
            IsSyncViewState = false;
        }
    }
}
